<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\LearnVideoStoreRequest;
use App\Models\LearnVideo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class LearnVideoController extends AdminBaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return JsonResponse|object
     */
    public function index()
    {
        $list = LearnVideo::filter(\request()->all())->orderByRaw('id desc')->paginate(\request('perPage', 10));
        return $this->restful($list);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param LearnVideoStoreRequest $request
     * @return JsonResponse|object
     */
    public function store(LearnVideoStoreRequest $request)
    {
        $params = $request->validated();

        $learnVideo = LearnVideo::create($params);

        return $this->restful($learnVideo);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param LearnVideoStoreRequest $request
     * @param int $id
     * @return JsonResponse|object
     */
    public function update(LearnVideoStoreRequest $request, $id)
    {
        $params = $request->validated();

        $result = LearnVideo::where('id', $id)->update($params);

        return $this->restful($result);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return JsonResponse|object
     */
    public function destroy($id)
    {
        $result = LearnVideo::where('id', $id)->delete();

        return $this->restful($result);
    }

    public function getOptions()
    {
        $list = LearnVideo::select(['id as value', 'name as label'])->where('is_active', 1)->get()->toArray();

        return $this->restful($list);
    }
}
